# -*- makefile -*-

raw_tests = dir-empty-name dir-mk-tree dir-mkdir dir-open		\
dir-over-file dir-rm-cwd dir-rm-parent dir-rm-root dir-rm-tree		\
dir-rmdir dir-under-file dir-vine grow-create grow-dir-lg		\
grow-file-size grow-root-lg grow-root-sm grow-seq-lg grow-seq-sm	\
grow-sparse grow-tell grow-two-files syn-rw

tests/filesys/extended_TESTS = $(patsubst %,tests/filesys/extended/%,$(raw_tests))
tests/filesys/extended_EXTRA_GRADES = $(patsubst %,tests/filesys/extended/%-persistence,$(raw_tests))

tests/filesys/extended_PROGS = $(tests/filesys/extended_TESTS) \
tests/filesys/extended/child-syn-rw tests/filesys/extended/tar

$(foreach prog,$(tests/filesys/extended_PROGS),			\
	$(eval $(prog)_SRC += $(prog).c tests/lib.c tests/filesys/seq-test.c))
$(foreach prog,$(tests/filesys/extended_TESTS),		\
	$(eval $(prog)_SRC += tests/main.c))
$(foreach prog,$(tests/filesys/extended_TESTS),		\
	$(eval $(prog)_PUTFILES += tests/filesys/extended/tar))
# The version of GNU make 3.80 on vine barfs if this is split at
# the last comma.
$(foreach test,$(tests/filesys/extended_TESTS),$(eval $(test).output: FILESYSSOURCE = --disk=tmp.dsk))

tests/filesys/extended/dir-mk-tree_SRC += tests/filesys/extended/mk-tree.c
tests/filesys/extended/dir-rm-tree_SRC += tests/filesys/extended/mk-tree.c

tests/filesys/extended/syn-rw_PUTFILES += tests/filesys/extended/child-syn-rw

tests/filesys/extended/dir-vine.output: TIMEOUT = 150

GETTIMEOUT = 60

GETCMD = pintos -v -k -T $(GETTIMEOUT)
GETCMD += $(PINTOSOPTS)
GETCMD += $(SIMULATOR)
GETCMD += $(FILESYSSOURCE)
GETCMD += -g fs.tar -a $(TEST).tar
ifeq ($(filter vm, $(KERNEL_SUBDIRS)), vm)
GETCMD += --swap-size=4
endif
GETCMD += -- -q
GETCMD += $(KERNELFLAGS)
GETCMD += run 'tar fs.tar /'
GETCMD += < /dev/null
GETCMD += 2> $(TEST)-persistence.errors $(if $(VERBOSE),|tee,>) $(TEST)-persistence.output

tests/filesys/extended/%.output: kernel.bin
	rm -f tmp.dsk
	pintos-mkdisk tmp.dsk --filesys-size=2
	$(TESTCMD)
	$(GETCMD)
	rm -f tmp.dsk
$(foreach raw_test,$(raw_tests),$(eval tests/filesys/extended/$(raw_test)-persistence.output: tests/filesys/extended/$(raw_test).output))
$(foreach raw_test,$(raw_tests),$(eval tests/filesys/extended/$(raw_test)-persistence.result: tests/filesys/extended/$(raw_test).result))

TARS = $(addsuffix .tar,$(tests/filesys/extended_TESTS))

clean::
	rm -f $(TARS)
	rm -f tests/filesys/extended/can-rmdir-cwd
